//
//  XLTableViewCell.m
//  XiaoLianClient
//
//  Created by NanNan on 2019/8/23.
//  Copyright © 2019 xiaolian. All rights reserved.
//

#import "XLTableViewCell.h"

#define kDefaultTableViewCellHeight 44

@interface XLTableViewCell ()

@property (nonatomic, strong)UILabel *bottomLine;

@end

@implementation XLTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    return [[self class] cellWithTableView:tableView withLeftSpace:-1024];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView withLeftSpace:(float)left {
    static NSString * CellID;
    CellID  = NSStringFromClass([self class]);
    XLTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[[self class] alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (left != -1024) {
            [cell updateBottomLineWithLeftSpace:left];
        }
    }
    return cell;
}

+ (CGFloat)cellHeight {
    return kDefaultTableViewCellHeight;
}

+ (CGFloat)configureCell:(XLTableViewCell *)cell withModel:(id)model {
    return kDefaultTableViewCellHeight;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configUI];
    }
    return self;
}

- (void)configUI {
    
}

- (void)showBottomLine {
    if (!self.bottomLine) {
        [self updateBottomLineWithLeftSpace:0];
    }
    self.bottomLine.hidden = NO;
}

- (void)hiddenBottomLine {
    if (!self.bottomLine) {
        [self updateBottomLineWithLeftSpace:0];
    }
    self.bottomLine.hidden = YES;
}

- (void)updateBottomLineWithLeftSpace:(float)left {
    if (!self.bottomLine) {
        self.bottomLine = [[UILabel alloc] init];
        self.bottomLine.backgroundColor = COLOR_DEFAULT_SEPARATOR;
        [self.contentView addSubview:self.bottomLine];
    }
    [self.bottomLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(left);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
        make.height.mas_equalTo(0.5);
    }];
}

- (void)setDataWithSourceData:(id)model {
    
}

@end
